package com.example.project.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.example.project.entity.Logininfor;

/**
 * 系统访问日志情况信息 数据层
 * 
 * @author ruoyi
 */
@Mapper
public interface LogininforMapper {

	/**
	 * 新增系统登录日志
	 * 
	 * @param logininfor 访问日志对象
	 */
	@Insert("insert into t_logininfor (login_name, status, ipaddr, login_location, browser, os, msg, login_time) "
			+ "values (#{loginName}, #{status}, #{ipaddr}, #{loginLocation}, #{browser}, #{os}, #{msg}, sysdate())")
	public void insertLogininfor(Logininfor logininfor);

	/**
	 * 查询系统登录日志集合
	 * 
	 * @param logininfor 访问日志对象
	 * @return 登录记录集合
	 */
	@Select("<script>select info_id,login_name,ipaddr,login_location,browser,os,status,msg,login_time from t_logininfor"
			+ "<where>"
			+ "<if test=\"ipaddr != null and ipaddr != ''\">AND ipaddr like concat('%', #{ipaddr}, '%')</if>"
			+ "<if test=\"status != null and status != ''\">AND status = #{status}</if>"
			+ "<if test=\"loginName != null and loginName != ''\">AND login_name like concat('%', #{loginName}, '%')</if>"
			+ "<if test=\"params.beginTime != null and params.beginTime != ''\">AND login_time &gt;= #{params.beginTime}</if>"
			+ "<if test=\"params.endTime != null and params.endTime != ''\">AND login_time &lt;= #{params.endTime}</if>"
			+ "</where></script>")
	public List<Logininfor> selectLogininforList(Logininfor logininfor);

	/**
	 * 批量删除系统登录日志
	 * 
	 * @param ids 需要删除的数据
	 * @return 结果
	 */
	@Delete("<script>delete from t_logininfor where info_id in"
			+ "<foreach collection=\"array\" item=\"infoId\" open=\"(\" separator=\",\" close=\")\">" + "#{infoId}"
			+ "</foreach></script>")
	public int deleteLogininforByIds(String[] ids);

	/**
	 * 清空系统登录日志
	 * 
	 * @return 结果
	 */
	@Update("truncate table t_logininfor")
	public int cleanLogininfor();
}
